package main

import (
	"flag"
	"log"
	"path/filepath"
	"web2pdf/lib"
)

var link, linkFile, targetPdf string
var linkSlice []string
var err error

func main() {
	flag.StringVar(&link, "url", "", "single url")
	flag.StringVar(&linkFile, "file", "", "url file, one url each line")
	flag.StringVar(&targetPdf, "pdf", "web2pdf.pdf", "generated pdf file name")
	flag.Parse()
	if link == "" && linkFile == "" {
		log.Fatalln("neither url nor file empty")
	}
	if !filepath.IsAbs(targetPdf) {
		targetPdf, _ = filepath.Abs(targetPdf)
	}
	if linkFile != "" {
		if !filepath.IsAbs(linkFile) {
			linkFile, err = filepath.Abs(linkFile)
			if err != nil {
				log.Fatalf("error in get absolute file path: %v\n", err)
			}
		}
		linkSlice = lib.ReadFileLinks(linkFile)
		lib.Run(linkSlice, targetPdf)
		return
	}
	linkSlice = []string{link}
	lib.Run(linkSlice, targetPdf)
}
